﻿var bodyCss = {
    position: 'relative',
    width: '100%',
    "min-height": '100%',
    "padding-bottom": '60px'
};

var footerCss = {
    height: '60px',
    position: 'fixed',
    bottom: '0px',
    'text-align': 'center',
    'line-height': '60px',
    left: '0px',
    'background-color': '#1266ce',
    color: 'white',
    width: '100%'
};


var labelCss = {
    'line-height': '60px',
    'text-align': 'right',
    'color': 'black'
}

var orgNameCss = {
    'line-height': '20px',
    'text-align': 'left'
}

var footerLastChildCss = {
    'line-height': '60px',
    'text-align': 'center',
    'font-size': '50px'
}

var footerACss = {
    color: 'black'
}


$(document).ready(function () {

    var content = $("<div class='footer container-fluid'>" +
                     "<div class='col-xs-7'>" +
                     "<label class='col-xs-3'>客户:</label>" +
                     "<div class='col-xs-9'><ul id='orgNames' class='list-unstyled'></ul></div> " +
                     "</div>" +
                     "<div class='col-xs-5 footerLastChildCss'>" +
                     "<a href='/Join/Success'>Join Now</a>" +
                     "</div>" +
                     "</div>");
    content.css(footerCss);
    content.find('label').css(labelCss);
    content.find('#orgNames').css(orgNameCss);
    content.find('.footerLastChildCss').css(footerLastChildCss);
    content.find('a').css(footerACss);
    $("body").append(content);
    $("body").css(bodyCss);

    $.ajax({
        url: "/Account/GetOrgizaions?ran=" + Math.random(),
        dataType: "json",
        type: "GET",
        success: function (data) {
            $.each(data, function (index, item) {
                orgList.push(item.Name);
                if (index < 3) {
                    $("#orgNames").append($("<li>" + item.Name + "</li>"));
                }
            })
        }
    });
    setInterval("GetOrgizations()", 3000);

})
var orgList = new Array();
var position = 0;
function GetOrgizations() {
    //todo: 算法改造
    if (position + 2 < orgList.length) {
        $("#orgNames").html("");
        $("#orgNames").append($("<li>" + orgList[position] + "</li>"));
        $("#orgNames").append($("<li>" + orgList[position + 1] + "</li>"));
        $("#orgNames").append($("<li>" + orgList[position + 2] + "</li>"));
        position = position + 2;

    } else {
        if (orgList.length - position == 1) {
            $("#orgNames").html("");
            $("#orgNames").append($("<li>" + orgList[position] + "</li>"));
            $("#orgNames").append($("<li>" + orgList[0] + "</li>"));
            $("#orgNames").append($("<li>" + orgList[1] + "</li>"));
            position = 1;
        }

        if (orgList.length - position == 2) {
            $("#orgNames").html("");
            $("#orgNames").append($("<li>" + orgList[position] + "</li>"));
            position++;
            $("#orgNames").append($("<li>" + orgList[position] + "</li>"));
            $("#orgNames").append($("<li>" + orgList[0] + "</li>"));
            position = 0;
        }
    }
}

